<?php

namespace app\common\model\Product;

use think\Model;

class Type extends Model
{
    //
    protected $name = 'product_type';

    protected $append = [
        'thumb_text'
    ];

    public function getThumbTextAttr($value, $data)
    {
        //获取到cdn的地址
        $cdnurl = config('site.cdnurl') ? config('site.cdnurl') : '';
        $cdnurl = trim($cdnurl, '/');
        
        $thumb = isset($data['thumb']) ? $data['thumb'] : '';

        //如果为空就给一个默认图片地址
        if(empty($thumb) || !@is_file(".".$thumb))
        {
            $thumb = "/assets/img/type.png";
        }

        return $cdnurl.$thumb;
    }
}
